package PagePackage;

import static org.testng.AssertJUnit.assertEquals;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class userContactInfoPageClass extends internalPageClass {
	@FindBy (xpath="html/body/div[1]/div/section/div/div/ul/li[1]/a")
	public WebElement contactinfotab;
	
	
	@FindBy (xpath="html/body/main/section/aside/nav/ul/li[2]/a")
	public WebElement roletab;
	
	@FindBy (className="pull-right")
	public WebElement canceluser;
	
	@FindBy (xpath="html/body/main/section/main/form/button[1]")
	public WebElement saveUser;
	
	
	@FindBy (name="firstName")
	public WebElement firstName;
	
	@FindBy (name="lastName")
	public WebElement lastName;
	
	@FindBy (name="email")
	public WebElement emailField;
	
	@FindBy (name="phone1")
	public WebElement phone1Field;
	
	@FindBy (name="phone2")
	public WebElement phone2Field;
	
	@FindBy (xpath="html/body/x-alertbar/div[1]/div")
	public WebElement notification;
	
	@FindBy (xpath="html/body/main/section/main/form/button[2]")
	public WebElement lockButton;
	
	public userRolePageClass roleTabClick() {
		roletab.click();
		
		return MyPageFactory.getPage(driver, userRolePageClass.class);
	}
	
	public userContactInfoPageClass getTextNotification() {
		notification.getText();
		assertEquals("This user is locked", notification.getText());
		return MyPageFactory.getPage(driver, userContactInfoPageClass.class);
	}
	
	
	public userContactInfoPageClass firstName(String firstNameName) {
		firstName.click();
		firstName.clear();
		firstName.sendKeys(firstNameName);
		return MyPageFactory.getPage(driver, userContactInfoPageClass.class);
	}
	
	public userContactInfoPageClass lastName(String lastNameName) {
		lastName.click();
		lastName.clear();
		lastName.sendKeys(lastNameName);
		return MyPageFactory.getPage(driver, userContactInfoPageClass.class);
	}
	
	public userContactInfoPageClass email(String emailName) {
		emailField.click();
		emailField.clear();
		emailField.sendKeys(emailName);
		return MyPageFactory.getPage(driver, userContactInfoPageClass.class);
	}
	
	public userContactInfoPageClass phone1 (String phone1Name) {
		phone1Field.click();
		phone1Field.clear();
		phone1Field.sendKeys(phone1Name);
		return MyPageFactory.getPage(driver, userContactInfoPageClass.class);
	}
	

	public userContactInfoPageClass phone2 (String phone2Name) {
		phone2Field.click();
		phone2Field.clear();
		phone2Field.sendKeys(phone2Name);
		return MyPageFactory.getPage(driver, userContactInfoPageClass.class);
	}
	
	public usersPageClass lockUnlock() {
       lockButton.click();
       lockButton.click();
       saveUser.click();
	
		return MyPageFactory.getPage(driver, usersPageClass.class);
	}
	
	public userContactInfoPageClass notificationAbsents() {
		 boolean present;
		    try {
		    	notification.getText();
				assertEquals("This user is locked", notification.getText());
	  
	      present = true;
	   } catch (NoSuchElementException e) {
	      present = false;
	   }
		    assertEquals(false, present);
		 return MyPageFactory.getPage(driver, userContactInfoPageClass.class);
		 
	}
	public boolean isOnThisPage(){
		return roletab.isDisplayed();
	}
	 @Override
		void tryToOpen() {
		 goToMainPage();
		 MyPageFactory.getPage(driver, loginPageClass.class).loginAs("victoria@krossover.com", "webmaster");
		}
	
	
}
